﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _010_异常处理
{
    class Program
    {
        static void Main(string[] args)
        {
            //string 的list泛型
            List<string> strList = new List<string>();
            strList.Add("32a");
            strList.Add("1c");
            strList.Add("f88");
            strList.Add("9d");
            strList.Add("w46");

            //排序
            strList.Sort(new StringComparel());
            foreach(var str in strList)
            {
                Console.WriteLine(str);
            }
            //猜你的代码有可能发生异常
            try
            {
                int a = 1;
                int b = 0;
                int c = a / b;
                Console.WriteLine("执行到这里1");
            }
            //捕获到异常的时候进行简单的处理
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("执行到这里了2");

            Console.ReadKey();
        }

        public class StringComparel : IComparer<string>
        {
            //实现了这个接口的方法
            public int Compare(string x, string y)
            {
                char x1 = char.Parse(x.Substring(0, 1));
                char y1 = char.Parse(y.Substring(0, 1));
                if (x1 < y1)
                {
                    return 1;
                }
                else if (x1 == y1)
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
        }
    }
}
